XSLT
XSLT (Extensible Stylesheet Language Transformations) is a declarative, XML-based language used for the transformation of XML documents into other XML documents. XSLT may also be used to output non-XML data, such as HTML, plain text or binary data, from an input XML document. XSLT is also used to translate XML messages between different schemas, or to format an XML document correctly. Overview The XSLT processing model involves: * one or more XML source documents; * one or more XSLT stylesheet modules; * the XSLT template processing engine (the processor); and * one or more result documents. The XSLT processor ordinarily takes two input documents—an XML source document, and an XSLT stylesheet—and produces an output document. The XSLT stylesheet contains a collection of template rules: instructions and other directives that guide the processor in the production of the output document. Template rule processing The XSLT language is declarative—rather than listing an imperative sequence of actions to perform in a stateful environment, template rules only define how to handle a node matching a particular XPath-like pattern, if the processor should happen to encounter one, and the contents of the templates effectively comprise functional expressions that directly represent their evaluated form: the result tree, which is the basis of the processor's output. The processor follows a fixed algorithm: Assuming a stylesheet has already been read and prepared, the processor builds a source tree from the input XML document. It then starts by processing the source tree's root node, finding in the stylesheet the best-matching template for that node, and evaluating the template's contents. Instructions in each template generally direct the processor to either create nodes in the result tree, or process more nodes in the source tree in the same way as the root node. Output is derived from the result tree. XSLT uses the halfway-to-even ("banker's") method when rounding fractional numbers to integers. XSLT and XPath XSLT relies upon the W3C's XPath language for identifying subsets of the source document tree, as well as for performing calculations. XPath also provides a range of functions, which XSLT itself further augments. This reliance upon XPath adds a great deal of power and flexibility to XSLT. XSLT 1.0 uses XPath 1.0. Similarly, XSLT 2.0 relies on XPath 2.0; both specifications were published on the same date. Syntax An XSLT stylesheet is an XML document containing the root node xsl:stylesheet or xsl:transform (synonymous to each other), where the xsl namespace is the XSLT namespace defined with the URI xmlns:xsl=http://www.w3.org/1999/XSL/Transform. ... Patterns A pattern is an XPath expression that matches a corresponding node in the source document. Templates A template (defined by xsl:template) declaration contains rules for creating nodes and values such as text and numbers. A template declaration usually has the match attribute, which contains a pattern to match the template with. Matched nodes on the source document will be evaluated by the contents of the template element to transform into output. External links * XSLT 1.0 W3C Recommendation * XSLT 2.0 W3C Recommendation Category:XML-based file formats